var t = getApp();

Page({
    data: {
        settingData: {},
        pricesList: [],
        autoOn: !1,
        alertOn: !1,
        editDialog: "",
        city: "",
        province: ""
    },
    autoSwitchChange: function(t) {
        this.changeAutoSwitch(t.detail.value ? "1" : "0");
    },
    alertSwitchChange: function(t) {
        this.changeAlertSwitch(t.detail.value ? "1" : "0");
    },
    clickDel: function(t) {
        var a = t.currentTarget.dataset.city, e = t.currentTarget.dataset.province, i = t.currentTarget.dataset.index, n = this;
        wx.showModal({
            title: "提示",
            content: "确定删除 " + a + " 的接单价格",
            success: function(t) {
                t.confirm && n.delCityPrice(e, a, i);
            }
        });
    },
    clickAdd: function(t) {
        wx.navigateTo({
            url: "/pages/sendOrder/selectCity/selectCity"
        });
    },
    clickEdit: function(t) {
        var a = t.currentTarget.dataset.city, e = t.currentTarget.dataset.province, i = t.currentTarget.dataset.index;
        this.setData({
            city: a,
            province: e,
            index: i
        }), this.editDialog = this.selectComponent("#addPriceDialog"), this.editDialog.showDialog();
    },
    priceAddOk: function(t) {
        this.editDialog.hideDialog();
        var a = t.detail;
        this.editCityPrice(this.data.province, this.data.city, a.marketPrice, a.cooperatePrice, this.data.index);
    },
    priceAddCancel: function(t) {
        this.editDialog.hideDialog();
    },
    getSettingData: function() {
        var a = this;
        t.network.post({
            url: t.url.GetWeddingOrderSetInfo,
            params: {},
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(e) {
                1 == e.data.result ? a.setData({
                    settingData: e.data.data,
                    autoOn: "1" == e.data.data.autoQiangDan,
                    alertOn: "1" == e.data.data.qiangDanAlert
                }) : t.util.showToast(e.data.message);
            },
            fail: function() {
                t.util.showToast("加载设置失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading();
            }
        });
    },
    getCityPriceData: function() {
        var a = this;
        t.network.post({
            url: t.url.GetWeddingOrderUserPriceList,
            params: {},
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(e) {
                1 == e.data.result ? a.setData({
                    pricesList: e.data.data.cityPrices
                }) : t.util.showToast(e.data.message);
            },
            fail: function() {
                t.util.showToast("获取城市价格失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading();
            }
        });
    },
    changeAutoSwitch: function(a) {
        var e = this;
        t.network.post({
            url: t.url.SetWeddingOrderAutoQiangDan,
            params: {
                autoQiangDan: a
            },
            before: function() {
                wx.showLoading({
                    title: "正在修改"
                });
            },
            success: function(a) {
                if (wx.hideLoading(), 1 == a.data.result) e.autoOn ? t.util.showToast(a.data.message) : wx.showModal({
                    title: "提示",
                    content: a.data.message,
                    showCancel: !1
                }); else if (3 == a.data.result) {
                    var i = a.data;
                    wx.showModal({
                        title: "提示",
                        content: i.message,
                        cancelText: "查看规则",
                        confirmText: "知道了",
                        success: function(t) {
                            t.cancel && wx.navigateTo({
                                url: "/pages/web/web?url=" + i.data.scheduleAccurateUrl
                            });
                        }
                    }), e.setData({
                        autoOn: !1
                    });
                } else wx.showModal({
                    title: "提示",
                    content: a.data.message,
                    showCancel: !1
                }), e.setData({
                    autoOn: !1
                });
            },
            fail: function() {
                wx.hideLoading(), t.util.showToast("修改失败");
            },
            complete: function() {}
        });
    },
    changeAlertSwitch: function(a) {
        t.network.post({
            url: t.url.SetWeddingOrderQiangDanAlert,
            params: {
                qiangDanAlert: a
            },
            before: function() {
                wx.showLoading({
                    title: "正在修改"
                });
            },
            success: function(a) {
                wx.hideLoading(), t.util.showToast(a.data.message);
            },
            fail: function() {
                wx.hideLoading(), t.util.showToast("修改失败");
            },
            complete: function() {}
        });
    },
    delCityPrice: function(a, e, i) {
        var n = this;
        t.network.post({
            url: t.url.DeleteWeddingOrderUserPrice,
            params: {
                province: a,
                city: e
            },
            before: function() {
                wx.showLoading({
                    title: "正在删除"
                });
            },
            success: function(a) {
                1 == a.data.result ? n.delLocalCity(i) : t.util.showToast(a.data.message);
            },
            fail: function() {
                t.util.showToast("加载设置失败");
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    editCityPrice: function(a, e, i, n, o) {
        var s = this;
        t.network.post({
            url: t.url.EditWeddingOrderUserPrice,
            params: {
                province: a,
                city: e,
                cooperationPrice: n,
                marketPrice: i
            },
            before: function() {
                wx.showLoading({
                    title: "正在修改"
                });
            },
            success: function(a) {
                1 == a.data.result ? s.editLocalCity(i, n, o) : t.util.showToast(a.data.message);
            },
            fail: function() {
                t.util.showToast("加载设置失败");
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    delLocalCity: function(t) {
        var a = this.data.pricesList;
        a.splice(t, 1), this.setData({
            pricesList: a
        });
    },
    editLocalCity: function(t, a, e) {
        var i = this.data.pricesList;
        i[e].marketPrice = t, i[e].cooperationPrice = a, this.setData({
            pricesList: i
        });
    },
    onLoad: function(t) {
        this.getSettingData();
    },
    onReady: function() {},
    onShow: function() {
        this.getCityPriceData();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});